package demo5;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-02-09
 * Time: 23:49
 */
class Animal{
    public String name;

    public Animal(String name) {
        this.name = name;
    }
}

//不是所有的动物都会飞，所以不能写到Animal类中。
//写到另一个类中也不行，因为一个类不能继承多个类，所以使用接口实现。
interface IFlying{
    void fly();
}
//跑的接口
interface IRunning{
    void run();
}
//游泳的接口
interface ISwimming{
    void swim();
}
//鸟会飞
class Bird extends Animal implements IFlying{
    public Bird(String name) {
        super(name);
    }
    @Override
    public void fly() {
        System.out.println(this.name+"正在飞");
    }
}
//青蛙会跑、会游戏
class Frog extends Animal implements IRunning,ISwimming{
    public Frog(String name) {
        super(name);
    }
    @Override
    public void run() {
        System.out.println(this.name+"正在跑");
    }
    @Override
    public void swim() {
        System.out.println(this.name+"正在游泳");
    }
}
//鸭子会跑、会飞、会游泳
class Duck extends Animal implements IRunning,IFlying,ISwimming{
    public Duck(String name){
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name+"正在跑");
    }

    @Override
    public void fly() {
        System.out.println(this.name+"正在飞");
    }

    @Override
    public void swim() {
        System.out.println(this.name+"正在游泳");
    }
}
public class Test1 {
    //调用飞的方法
    public static void Flyingfunc(IFlying iFlying){
        iFlying.fly();
    }
    //调用跑的方法
    public static void Runningfunc(IRunning iRunning){
        iRunning.run();
    }
    //调用游泳的方法
    public static void Swimmingfunc(ISwimming iSwimming){
        iSwimming.swim();
    }
    public static void main(String[] args) {
        /*Bird bird = new Bird("小鸟");
        Flyingfunc(bird);*/
        Flyingfunc(new Bird("小鸟"));

        Flyingfunc(new Duck("鸭子"));
        Runningfunc(new Duck("鸭子"));
        Swimmingfunc(new Duck("鸭子"));

        Runningfunc(new Frog("青蛙"));
        Swimmingfunc(new Duck("青蛙"));
    }
}
